package com.lee.single.starter.response.exception;

import com.lee.single.starter.response.constant.ResultCodeConstants;
import lombok.Getter;

/**
 * @author lee
 * @since 2019-11-22
 */
@Getter
public class AppException extends RuntimeException {

    private final int code;
    private final String msg;

    public AppException(String msg) {
        this(ResultCodeConstants.COMMON_ERROR, msg);
    }

    public AppException(int code) {
        this(code, defaultMsg(code));
    }

    public AppException(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static String defaultMsg(int code) {
        switch (code){
            case ResultCodeConstants.NOT_LOGIN:
                return "请先登录";
            case ResultCodeConstants.NOT_ALLOWED:
                return "无权访问，请联系管理员";
            case ResultCodeConstants.ERROR_UNKNOWN:
            default:
                return "服务处正忙，请稍后再试";
        }
    }

}
